package com.xcx.services.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.xcx.bo.CommConfig;
import com.xcx.bo.CommConfigExample;
import com.xcx.common.enums.CommConfigParamKeyEnum;
import com.xcx.common.enums.IsValidEnum;
import com.xcx.common.services.common.CommConfigService;
import com.xcx.common.utils.CollectionsUtils;
import com.xcx.dao.CommConfigDao;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;
import java.util.List;


/**
 * 公共配置类
 */
@Slf4j
@Service
public class CommConfigServiceImpl implements CommConfigService {


    @Resource
    private CommConfigDao commConfigDao;


    /**
     * 通过产品编号和key获得参数值
     *
     * @param commConfigParamKeyEnum
     * @return
     */
    @Override
    public String queryParamValue(CommConfigParamKeyEnum commConfigParamKeyEnum) {
        log.info("queryParamValue productCode:{} paramKey:{}", commConfigParamKeyEnum.getProductCode(), commConfigParamKeyEnum.getParamKey());
        CommConfigExample example = new CommConfigExample();
        example.createCriteria()
                .andProductCodeEqualTo(commConfigParamKeyEnum.getProductCode())
                .andParamKeyEqualTo(commConfigParamKeyEnum.getParamKey())
                .andParamStatusEqualTo(IsValidEnum.VALID_YES.getCode());
        List<CommConfig> lst = commConfigDao.selectByExample(example);
        return CollectionsUtils.isEmpty(lst) && lst.size() == 0 ? null : lst.get(0).getParamValue();
    }
}
